﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using TyMES.Model.Record;


namespace TyMES.ViewModel.Record.ScanMaterialSNVMs
{
    public partial class ScanMaterialSNListVM : BasePagedListVM<ScanMaterialSN_View, ScanMaterialSNSearcher>
    {

        protected override IEnumerable<IGridColumn<ScanMaterialSN_View>> InitGridHeader()
        {
            return new List<GridColumn<ScanMaterialSN_View>>{
                this.MakeGridHeader(x => x.lineCode),
                this.MakeGridHeader(x => x.stationCode),
                this.MakeGridHeader(x => x.operationCode),
                this.MakeGridHeader(x => x.assemblyMaterialCode),
                this.MakeGridHeader(x => x.assemblyMaterialName),
                this.MakeGridHeader(x => x.assemblyMaterialSN),
                this.MakeGridHeader(x => x.sort),
                this.MakeGridHeader(x => x.batchCode),
                this.MakeGridHeader(x => x.BindTime),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<ScanMaterialSN_View> GetSearchQuery()
        {
            var query = DC.Set<ScanMaterialSN>()
                .CheckContain(Searcher.lineCode, x=>x.lineCode)
                .CheckContain(Searcher.stationCode, x=>x.stationCode)
                .CheckContain(Searcher.operationCode, x=>x.operationCode)
                .CheckContain(Searcher.assemblyMaterialCode, x=>x.assemblyMaterialCode)
                .CheckContain(Searcher.assemblyMaterialName, x=>x.assemblyMaterialName)
                .CheckContain(Searcher.assemblyMaterialSN, x=>x.assemblyMaterialSN)
                .CheckContain(Searcher.sort, x=>x.sort)
                .CheckContain(Searcher.batchCode, x=>x.batchCode)
                .CheckBetween(Searcher.BindTime?.GetStartTime(), Searcher.BindTime?.GetEndTime(), x => x.BindTime, includeMax: false)
                .Select(x => new ScanMaterialSN_View
                {
				    ID = x.ID,
                    lineCode = x.lineCode,
                    stationCode = x.stationCode,
                    operationCode = x.operationCode,
                    assemblyMaterialCode = x.assemblyMaterialCode,
                    assemblyMaterialName = x.assemblyMaterialName,
                    assemblyMaterialSN = x.assemblyMaterialSN,
                    sort = x.sort,
                    batchCode = x.batchCode,
                    BindTime = x.BindTime,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class ScanMaterialSN_View : ScanMaterialSN{

    }
}
